package com.example.pcl.service.impl;

import com.example.pcl.mapper.AppointmentsMapper;
import com.example.pcl.mapper.StudentFeedbackMapper;
import com.example.pcl.pojo.entity.Appointments;
import com.example.pcl.service.HomeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class HomeServiceImpl implements HomeService {
    private final AppointmentsMapper appointmentMapper;
    private final StudentFeedbackMapper feedbackMapper;

    @Override
    public Map<String, Object> getStatistics() {
        Map<String, Object> statistics = new HashMap<>();

        // 总咨询量
        int totalConsultations = appointmentMapper.countTotalAppointments();

        // 查询已完成的咨询量
        int completedAppointments = appointmentMapper.countCompletedAppointments(Appointments.COMPLETED);
        // 总好评率
        double totalRating = feedbackMapper.calculateOverallRating();

        // 待确认预约
        int pendingAppointments = appointmentMapper.countPendingAppointments(Appointments.TO_BE_CONFIRMED);


        // 获取咨询师好评率数据
        List<Map<String, Object>> ratingData = feedbackMapper.getConsultantRatingData();

        statistics.put("totalConsultations", totalConsultations);
        statistics.put("totalRating", totalRating);
        statistics.put("pendingAppointments", pendingAppointments);
        statistics.put("completedAppointments", completedAppointments);
        statistics.put("ratingData", ratingData);

        return statistics;
    }
}
